#pragma once

#include <map>
#include <vector>
#include <atltypes.h>
#include <string>


//------------------------------------------------------
// foreword declaration
//------------------------------------------------------
struct STab;
typedef int TAB_ID;
typedef std::vector<TAB_ID>			TAB_ORDER;
typedef std::map<TAB_ID, STab>		TAB_COLLECTION;

struct STab
{
	bool	m_visible;
	bool    m_active;
	bool    m_lock;
	int		m_data;
	int		m_id;	
	void    *m_pVoid;
	CRect   m_rctTabInHost;	
};


//------------------------------------------------------
// CTabActionWatcher
//------------------------------------------------------
class CTabActionWatcher
{
public:
	virtual ~CTabActionWatcher(){}

	virtual void OnTabClick(int id) = 0;
	virtual void OnTabDblClick(int id) = 0;
	virtual void OnTabClose(int id) = 0;
	virtual void OnTabHide(int id) = 0;
};


//------------------------------------------------------
// CTabHost
//------------------------------------------------------
class CTabHost
{
public:
	static CTabHost* GetTabHostInstance(HWND hWndMain);
	static void	  ReleaseTabHost();

private:
	static LRESULT __stdcall HostWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
	static CTabHost		*sm_pTabHost;
	CTabHost();
	~CTabHost();

public:
	void		 Init(HWND hWndMain);
	bool		 ActivateTab(int id);
	int			 GetActivateTab(){return m_activeTabId;};
	bool		 ShowTab(int id, bool show);
	bool		 ShowHost(bool show);
	void		 DrawAllTabs(bool bDraw, bool bUpdate);

	bool		 PushNewTab(int id);
	bool		 RemoveTab(int id);

	void		 SetTabActionWacther(CTabActionWatcher *watcher);	
	CRect        GetTabHostPosSize();
	void		 ResizeTabHost(CSize szNew, CPoint *pLeftTop);

private:
	void		 ArrangeTabPos();
	LRESULT		 WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

private:
	bool				m_bAutoHide;		// disabled now
	bool				m_bVisible;
	int					m_mouseDownTabId;
	int					m_activeTabId;
	int					m_tabsPosOffset;	// the real left and right of STab::m_rctTabInHost must add this value

	CSize				m_szMemDc;
	HDC					m_hMemDc;
	HWND				m_hWndParentMain;
	HWND				m_hWndTabsHost;

	CTabActionWatcher	*m_pTabWatcher;
	TAB_COLLECTION		m_tabs;	
	TAB_ORDER			m_order;
};

